//
//  GameManager.cpp
//  fingeradvanture
//
//  Created by shuaibincheng on 16/5/1.
//
//

#include "GameManager.hpp"
#include "MonsterDen.hpp"
#include "GameHero.hpp"

USING_NS_CC;

GameManager *GameManager::mangaer = 0;
GameManager *GameManager::getInstance()
{
    if(!mangaer)
    {
        mangaer = new GameManager;
    }
    return mangaer;
}


GameManager::GameManager(){
    this->field = new BattleField;
}
GameManager::~GameManager(){
    if(this->field)
        delete this->field;
}

void GameManager::heroEnter(){
    CCLOG("a hero enters");
    
    if(Director::getInstance()->isPaused())
    {
        //an hero is already be there, we just need to resume the game
        this->gameResume();
    }
    else
    {
        //an hero has entered, so let's begin the game
        this->gameStart();

    }
}

void GameManager::heroExit(){
    CCLOG("a hero exits");
    
    //the hero has exited, so we need to pause the game
    this->gamePause();
}

void GameManager::heroDied()
{
    CCLOG("the hero died");
    this->gamePause();
}

BattleField *GameManager::getBattleField()
{
    return this->field;
}

void GameManager::gameStart()
{
    CCLOG("the game is going to stared");
    
    //create a hero for this game, and add it to the battle field
    GameHero *hero = new GameHero;
    this->field->setHero(hero);
    
    //we got a new hero, so let's notify the monsters
    /* to do */
    MonsterDen::getInstance()->notifyHeroEntered();
}

void GameManager::gamePause()
{
    CCLOG("the game has paused");
    Director::getInstance()->pause();
}

void GameManager::gameResume()
{
    CCLOG("the game has resumed");
    Director::getInstance()->resume();
}
void GameManager::gameStop()
{
    CCLOG("the game has stoped");
}